package com.polaris.live.adapter.level

import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.blankj.utilcode.util.StringUtils
import com.polaris.live.R
import com.polaris.live.common.ext.setOnSingleClickListener
import com.polaris.live.translation.R.string
import com.zhpan.bannerview.BaseBannerAdapter
import com.zhpan.bannerview.BaseViewHolder

/**
 * NewGuideBannerAdapter
 *
 * @author Created by 半仙 on 2024/1/17/017 10:06
 */
class NewGuideBannerAdapter : BaseBannerAdapter<String>() {
    override fun bindData(
        holder: BaseViewHolder<String>?,
        data: String?,
        position: Int,
        pageSize: Int,
    ) {
        holder?.apply {
            val tvTitle = findViewById<TextView>(R.id.tv_title)
            val ivCenter = findViewById<ImageView>(R.id.iv_center)
            val tvStartLive = findViewById<TextView>(R.id.tv_start_live)
            val tvCancel = findViewById<TextView>(R.id.tv_cancel)
            val tvBottom = findViewById<ImageView>(R.id.iv_bottom)
            when (position) {
                0 -> {
                    tvTitle.text = StringUtils.getString(string.now_start_live)
                    tvStartLive.text = StringUtils.getString(string.start_to_just_live)
                    ivCenter.setImageResource(R.drawable.img_tanchuang1)
                    tvCancel.visibility = View.INVISIBLE
                    tvBottom.visibility = View.VISIBLE
                }

                1 -> {
                    tvTitle.text = StringUtils.getString(string.win_beans_level_up)
                    tvStartLive.text = StringUtils.getString(string.look_anchor_level)
                    tvCancel.text = StringUtils.getString(string.start_to_just_live)
                    ivCenter.setImageResource(R.drawable.img_jiantou)
                    tvCancel.visibility = View.VISIBLE
                    tvBottom.visibility = View.GONE
                }

                2 -> {
                    tvTitle.text = StringUtils.getString(string.get_beans_to_first)
                    tvStartLive.text = StringUtils.getString(string.look_my_beans)
                    tvCancel.text = StringUtils.getString(string.start_to_just_live)
                    ivCenter.setImageResource(R.drawable.img_jinzhu)
                    tvCancel.visibility = View.VISIBLE
                    tvBottom.visibility = View.GONE
                }
            }
            tvStartLive.setOnSingleClickListener {
                onStartClick?.invoke(position)
            }
            tvCancel.setOnSingleClickListener {
                onCancelClick?.invoke(position)
            }
        }
    }

    private var onCancelClick: ((position: Int) -> Unit)? = null
    fun setOnCancelClick(l: (position: Int) -> Unit) {
        onCancelClick = l
    }

    private var onStartClick: ((position: Int) -> Unit)? = null
    fun setOnStartClick(l: (position: Int) -> Unit) {
        onStartClick = l
    }

    override fun getLayoutId(viewType: Int): Int {
        return R.layout.adapter_level_up_banner
    }
}